import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import VueMacros from 'unplugin-vue-macros/vite'


// https://vitejs.dev/config/
export default defineConfig({
    define: {
        __VUE_OPTIONS_API__: false,
        __VUE_PROD_DEVTOOLS__: false,
    },
    plugins: [
        //@ts-ignore
        VueMacros({
            setupComponent: false,
            setupSFC: false,
            plugins: {
                vue: vue(),
                vueJsx: vueJsx(),
            },
        }),
    ],
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url)),
            "~element-plus": fileURLToPath(new URL('./src/packages/element-plus/index.ts', import.meta.url)),
            '@element-plus/icons-vue': fileURLToPath(new URL('./node_modules/@element-plus/icons-vue/dist', import.meta.url)),
            "@element-plus": fileURLToPath(new URL('./src/packages', import.meta.url)),
        }
    },
    server: {
        cors: true, // 默认启用并允许任何源
        // open: true, // 在服务器启动时自动在浏览器中打开应用程序
        proxy: {
          '/api': {
            target: "",
            changeOrigin: true,
            rewrite: (path) => path.replace(/^\/api/, '')
          }
        }
    }
})
